using System;
using Holoville.HOTween;
using Holoville.HOTween.Core;
using UnityEngine;

public class ButtonTween : tk2dUIBaseItemControl
{
	public bool UseOnReleaseInsteadOfOnUp
	{
		get
		{
			return this.useOnReleaseInsteadOfOnUp;
		}
	}

	private void Awake()
	{
		this.onUpScale = base.transform.localScale;
	}

	private void OnEnable()
	{
		if (this.uiItem)
		{
			this.uiItem.OnDown += this.ButtonDown;
			if (this.useOnReleaseInsteadOfOnUp)
			{
				this.uiItem.OnRelease += this.ButtonUp;
			}
			else
			{
				this.uiItem.OnUp += this.ButtonUp;
			}
		}
		this.internalTweenInProgress = false;
		base.transform.localScale = this.onUpScale;
	}

	private void OnDisable()
	{
		if (this.uiItem)
		{
			this.uiItem.OnDown -= this.ButtonDown;
			if (this.useOnReleaseInsteadOfOnUp)
			{
				this.uiItem.OnRelease -= this.ButtonUp;
			}
			else
			{
				this.uiItem.OnUp -= this.ButtonUp;
			}
		}
	}

	private void ButtonDown()
	{
		if (this.tweenDuration <= 0f)
		{
			base.transform.localScale = this.onDownScale;
		}
		else
		{
			base.transform.localScale = this.onUpScale;
			this.tweenTargetScale = this.onDownScale;
			if (!this.internalTweenInProgress)
			{
				this.TweenButton();
				this.internalTweenInProgress = true;
			}
			else
			{
				HOTween.Complete(base.gameObject.name);
				this.TweenButton();
				this.internalTweenInProgress = true;
			}
		}
	}

	private void ButtonUp()
	{
		if (this.tweenDuration <= 0f)
		{
			base.transform.localScale = this.onUpScale;
		}
		else
		{
			this.tweenTargetScale = this.onUpScale;
			if (!this.internalTweenInProgress)
			{
				this.TweenButton();
				this.internalTweenInProgress = true;
			}
			else
			{
				HOTween.Complete(base.gameObject.name);
				this.TweenButton();
				this.internalTweenInProgress = true;
			}
		}
	}

	private void TweenButton()
	{
		TweenParms p_parms = new TweenParms().Prop("localScale", this.tweenTargetScale).Id(base.gameObject.name).Ease(EaseType.EaseOutElastic, 1.2f, 0.15f).OnComplete(new TweenDelegate.TweenCallback(this.OnCompleteTween));
		HOTween.To(this.uiItem.transform, this.tweenDuration, p_parms);
	}

	private void OnCompleteTween()
	{
		this.internalTweenInProgress = false;
	}

	public void InternalSetUseOnReleaseInsteadOfOnUp(bool state)
	{
		this.useOnReleaseInsteadOfOnUp = state;
	}

	public Vector3 onDownScale = new Vector3(0.9f, 0.9f, 0.9f);

	public float tweenDuration = 1.3f;

	private Vector3 onUpScale;

	private Vector3 tweenTargetScale = Vector3.one;

	[SerializeField]
	private bool useOnReleaseInsteadOfOnUp;

	private bool internalTweenInProgress;
}
